package com.luoc.base.utils;

import org.springframework.core.io.ClassPathResource;
import org.springframework.util.ResourceUtils;

import java.io.*;

/**
 * @Author: luoc
 * @Date: 2019/8/20 9:47
 * linux 获取jar中文件的不同方式
 */
public class ResourcePathUtil {

    //字符编码
    private static String ENCODING = "UTF-8";

    /**
     * @param fileName "classpath:SensitiveWord.txt"
     * @throws IOException
     */
    public static void getResourcePath(String fileName) throws IOException {
        String os = System.getProperty("os.name");
        InputStream stream = null;
        // windows
        if (os.contains("Windows")) {
            File file = ResourceUtils.getFile(fileName);
            stream = new FileInputStream(file);
        }

        // linux 路径
        if (os.contains("Linux")) {
            ClassPathResource classPathResource = new ClassPathResource(fileName);
            stream = classPathResource.getInputStream();
        }
        InputStreamReader read = new InputStreamReader(stream, ENCODING);
    }
}
